package lib.bone.audit.workload.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

/**
 * @author kindear
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "nepu_workload")
@EntityListeners(AuditingEntityListener.class)
@ApiModel(value = "工作量记录表")
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class NepuWorkload {

    public NepuWorkload(String workloadType,String workloadSource){

        this.workloadType = workloadType;
        this.workloadSource = workloadSource;

    };

    public NepuWorkload(Long userId,String workloadType,int usedUp){
        this.userId = userId;
        this.workloadType = workloadType;
        this.usedUp = usedUp;
    };

    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @ApiModelProperty(value = "工作量记录ID",name = "id")
    String id;

    /**
     * 工作量附加信息
     */
    @ApiModelProperty(value = "工作量记录附加信息",notes = "JsonObject -> Str")
    @Column(name = "workload_attach")
    String workloadAttach;

    @ApiModelProperty(value = "科研项目ID")
    @Column(name = "link_Id")
    String linkId;

//    @ApiModelProperty(value = "科研项目名称",notes = "缺省值 null")
//    @Column(name = "link_name")
//    String linkName;

    @ApiModelProperty(value = "工作量类型",notes = "科研工作量，教学工作量，管理工作量，兼职工作量")
    @Column(name = "workload_type")
    String workloadType;
    /**
     * 工作量来源统计
     */
    @ApiModelProperty(value = "工作量来源",notes = "负责人分配,管理员分配,申请获得")
    @Column(name = "workload_source")
    String workloadSource;

    /**
     * 工作量能否分配
     */
//    @ApiModelProperty(value = "工作量能否分配",notes = "1 为可分配 0 为不可分配")
//    @Column(name = "distribute_access")
//    Integer distributeAccess;


    /**
     * 工作量级别
     */
    @ApiModelProperty(value = "工作量级别",notes = "科研工作量专属字段，其余为缺省值*")
    @Column(name = "workload_level")
    String workloadLevel;

    /**
     * 工作量归属周期ID
     */
    @ApiModelProperty("周期ID")
    @Column(name = "cycle_id")
    String cycleId;

    /**
     * 工作量归属父周期ID
     */
    @ApiModelProperty(value = "父周期ID")
    @Column(name = "parent_id")
    String parentId;

    /**
     * 对应用户ID
     */
    @ApiModelProperty(value = "用户ID",notes = "对应 system-user 表 ID")
    @Column(name = "user_id")
    Long userId;


    @ApiModelProperty(value = "工作量",notes = "")
    @Column(name = "workload",scale = 2)
    Double workload;


    @ApiModelProperty(value = "已使用工作量",notes = "")
    @Column(name = "used_workload",scale = 2)
    Double usedWorkload;

    @ApiModelProperty(value = "用尽标识",notes = "1 为 用尽，0为未剩余")
    @Column(name = "used_up")
    Integer usedUp;

    /**
     * 3 : 可以分配 可以冲抵 可以转化
     * 2 : 可以分配 可以冲抵
     * 1 : 可以抵扣
     * 0 : 禁止任何查询之外的操作
     */
    @ApiModelProperty(value = "锁等级",notes = "0 ~ 3")
    @Column(name = "workload_lock")
    Integer workloadLock;

    @ApiModelProperty(value = "备注信息",notes = "")
    @Column(name = "remark")
    String remark;


    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;
    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        NepuWorkload that = (NepuWorkload) o;
        return id != null && Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
